package com.wc.alorithm_blue_bridge._数学知识.组合数.Q1457;

import java.util.*;

/**
 * @Author congege
 * @Description 杨辉三角形
 * https://www.lanqiao.cn/problems/1457/learning/?page=1&first_category_id=1&sort=students_count
 * @Date Created in 2023/9/16-16:34
 */


public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long n = scan.nextInt();
        boolean flg = true;
        // 存储最大列数
        int maxCol = Integer.MAX_VALUE;
        if (n == 1) {
            System.out.println(1);
            return;
        }
        // 存储上一行一半的数据
        ArrayList<Long> preRow = new ArrayList<>();
        preRow.add(1L);

        Long curNumber = 0l;
        // 代表楼层
        int floor = 1;

        while (flg) {
            floor++;
            // 当前楼层
            ArrayList<Long> row = new ArrayList<>();
            row.add(1L);
            int mid = floor / 2;

            for (int i = 1; i < mid && i < maxCol; i++) {
                curNumber = preRow.get(i) + preRow.get(i - 1);
                if (curNumber == n) {
                    System.out.println(floor * (floor - 1) / 2 + (i + 1));
                    return;
                }
                row.add(curNumber);
            }

            // 如果是奇数层是多一个的
            if (floor % 2 == 1) {
                curNumber = preRow.get(preRow.size() - 1) + preRow.get(preRow.size() - 1);
                if (curNumber == n) {
                    System.out.println(floor * (floor - 1) / 2 + mid + 1);
                    return;
                }
                row.add(curNumber);
            }

            // 当前数字表示的是当前行的最大值
            // 当最大值已经比n大了
            if (n < curNumber) {
                // 说明这个数字一定在前面几列了
                maxCol = row.size() - 1;

                // 这个就说明这个位置是在未来某一行的第二个位置
                if (maxCol == 2) {
                    System.out.println(n * (n + 1) / 2 + 2);
                    return;
                }
            }
            preRow = row;
        }
        scan.close();
    }
}
